from django.db import models
from django.contrib.auth.models import AbstractUser


# Create your models here.
class User(AbstractUser):
    """
    用户模型 继承了AbstractUser
    该模型拥有如下字段：
    username(unique)
    first_name
    last_name
    email(empty permit)
    password
    groups
    user_permissions
    is_staff
    is_active
    is_superuser
    last_login
    date_joined
    sex
    image
    birthday(DateField)
    phone
    location
    """
    SEX_UNKNOW = 0
    SEX_MALE = 1
    SEX_FEMALE = 2
    SEX_ITEMS = (
        (SEX_UNKNOW, "暂定"),
        (SEX_MALE, "男"),
        (SEX_FEMALE, "女")
    )
    sex = models.PositiveSmallIntegerField(default=SEX_UNKNOW, choices=SEX_ITEMS, verbose_name="性别")
    image = models.ImageField(upload_to='head_portrait', null=True, blank=True, verbose_name="头像")
    birthday = models.DateField(null=True, blank=True, verbose_name="生日")
    phone = models.CharField(max_length=20, blank=True, verbose_name="手机号码")
    location = models.CharField(max_length=80, blank=True, verbose_name="所在地")

    def __str__(self):
        return self.username

    class Meta:
        verbose_name = verbose_name_plural = "用户"
        ordering = ['-date_joined']
